package com.ftdc.app.yield;

public class YieldController {
    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("Thread 1 - Iteration " + i);
                Thread.yield(); // 提示调度器让出 CPU
            }
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("Thread 2 - Iteration " + i);
            }
        });

        thread1.start();
        thread2.start();
    }
}
